package com.hruiworks.campusgroup.algorithm.entity;

import lombok.Data;

import java.time.LocalDateTime;

/**
 * 时间点实体，用来判断多个时间段有没有重合
 */
@Data
public class TimePoint implements Comparable<TimePoint>{

    /**
     * 时间点的时间
     */
    private LocalDateTime time;


    /**
     * 该时间点是起始点还是结束点
     * true为开始，false为结束
     */
    private Boolean position;

    public TimePoint() {
    }

    public TimePoint(LocalDateTime time, Boolean position) {
        this.time = time;
        this.position = position;
    }

    /**
     * 重写比较方法
     * 时间小的返回在前，时间相同结束点在前
     * @param timePoint the object to be compared.
     * @return
     */
    @Override
    public int compareTo(TimePoint timePoint) {
        if (!this.time.isEqual(timePoint.time)) {
            if (this.time.isBefore(timePoint.time)) {
                return -1;
            } else {
                return 1;
            }
        } else {
            return Boolean.compare(!this.position, !timePoint.position); // 结束事件优先
        }
    }
}
